/*
 * lab9D1.c
 * CSIS 248 Operating System Programming
 */
#include <stdio.h>
#include <stdlib.h>

#define SIZE 10
#define EXTRA 20
int main(){
   double a[ SIZE ];

   // allocate memory for array "b"
   double* b = (double*) malloc( SIZE * sizeof(double) );
   if (b == NULL) {
	   fprintf(stderr, "Not able to allocate memory for b\n");
	   return -1;
   }

   // print the contents of arrays a and b
   int i=0;
   printf("a is %p\n   ", a);
   for ( ; i<SIZE+EXTRA; i++)
	   printf(" %f", a[i] );
   printf("\n");

   printf("b is %p\n   ", b);
   for ( i=0; i<SIZE+EXTRA; i++)
	   printf(" %f", b[i] );
   printf("\n");

   // Write to a and b
   for (i=0 ; i<SIZE+EXTRA; i++)
	   a[i] = 1;
   for ( i=0; i<SIZE+EXTRA; i++)
	   b[i] = 1;

   // return memory to the heap
   free( b );
   printf("b is %p\n   ", b);
   for ( i=0; i<SIZE; i++)
	   printf(" %f", b[i] );
   printf("\n");

   // return more memory to the heap!
   free( b );
   free( a );
   printf("a is %p\n   ", a);
   printf("b is %p\n   ", b);
}
